package com.cskaoyan.controller.wx_cart;

import com.cskaoyan.bean.wx_cart.Cart;
import com.cskaoyan.bean.wx_cart.vo.CartIndexVo;
import com.cskaoyan.bean.wx_resp.WxRespVo;
import com.cskaoyan.service.wx_cart.WxCartService2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 类<code>Doc</code>用于：TODO
 *
 * @author Acher
 * @version 1.0
 * @date 2021-10-22
 */
@RequestMapping("wx/cart")
@RestController
public class WxCartController2 {

    @Autowired
    WxCartService2 wxCartService2;

    @RequestMapping("index")
    // http://localhost:8083/wx/cart/index
    public WxRespVo index() {
        CartIndexVo cartIndexVo = wxCartService2.index();
        return WxRespVo.ok(cartIndexVo);
    }

    @PostMapping("update")
    // http://localhost:8083/wx/cart/update
    public WxRespVo update(@RequestBody Cart cart) {// 可以切面
        if (wxCartService2.update(cart))
            return WxRespVo.error("修改失败");
        return WxRespVo.ok();
    }

    @PostMapping("add")
    // http://localhost:8083/wx/cart/add
    public WxRespVo add(@RequestBody Cart cart) {
        int count = wxCartService2.add(cart);
        return WxRespVo.ok(count);
    }

    @RequestMapping("goodscount")
    // http://localhost:8083/wx/cart/goodscount
    public WxRespVo goodscount() {
        int goodsCount = wxCartService2.count();
        return WxRespVo.ok(goodsCount);
    }
}
